function getQuery(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return (false);
}

function $(id) {
    return document.getElementById(id);
}

function getFormData(param) {
    let formData = new FormData();

    for (var fieldName in param) {
        formData.append(fieldName, param[fieldName]);
    }
}

function getUploadConfig() {
    let config = {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }
    return config;
}

/**
 * 向服务器发送AJAX的上传文件POST请求
 * @param url URL地址
 * @param param 请求参数
 * @returns 响应信息消息体
 */
async function uploadAjaxPost(url, param) {
    var info = null;
    let formData = new FormData();

    for (var fieldName in param) {
        formData.append(fieldName, param[fieldName]);
    }
    let config = {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }

    await axios.post(url, formData, config).then(e => {
        info = e.data;
    });
    return info;
}

/**
 * 图片预览
 * @param fileId 文件表单ID
 * @param imgId 图片ID
 */
function fileChange(fileId, imgId) {
    var reader = new FileReader();//定义文件读取流对象
    reader.readAsDataURL(document.getElementById(fileId).files[0]);
    reader.onload = function (ev) {
        document.getElementById(imgId).src = ev.target.result;
    }
}